﻿<cfcomponent output="false">

	<cffunction name="init" access="public" returntype="FeedManager">
		
		<cfreturn this/>
	</cffunction>
	
	<cffunction name="createFeed" access="public" returntype="void" >
		<cfargument name="config" type="Component" required="true" />
		<cfargument name="posts" type="Array" required="true" />
		<cfscript>
		var i = 0;
		var myXML = "";
        var myStruct = structNew(); 
		
        mystruct.link = "http://#arguments.config.getLink()#"; 
        myStruct.title = arguments.config.getTitle(); 
        mystruct.description = arguments.config.getDescription(); 
        mystruct.pubDate = now(); 
        mystruct.version = "rss_2.0"; 
 
        myStruct.item = []; 
		
		for( i=1; i<=arrayLen( arguments.posts ); i++ ){
		
	        myStruct.item[i] = structNew(); 
	        myStruct.item[i].description = structNew(); 
	        myStruct.item[i].description.value = arguments.posts[i].getMainContent(); 
	        myStruct.item[i].link = "http://#arguments.config.getLink()#/post/idpost/#arguments.posts[i].getIdPost()#/#arguments.posts[i].getUrlSafe()#/"; 
	        myStruct.item[i].pubDate = lsParseDateTime( arguments.posts[i].getPublishingDate() ); 
	        myStruct.item[i].title = arguments.posts[i].getTitle(); 
		
		}
		
        </cfscript>
	
		<cffeed action = "create" 
		        name = "#myStruct#" 
		        outputFile = "#expandPath( 'feeds/EasyBlog.xml' )#"  
		        overwrite = "yes"
				xmlVar = "myXML" 
		        /> 
        
	</cffunction>

</cfcomponent>